package com.aznest.controller;
import com.aznest.context.BaseContext;
import com.aznest.entity.Type;
import com.aznest.entity.User;
import com.aznest.mapper.OrdersMapper;
import com.aznest.mapper.TypeMapper;
import com.aznest.result.Result;
import com.aznest.service.StatService;
import com.aznest.service.UserService;
import com.aznest.service.impl.StatServiceImpl;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 酒店统计相关接口
 **/
@RestController
@RequestMapping("/statistics")
@Api(tags = "酒店统计相关接口")
@Slf4j
public class StatController {

    @Resource
    private StatService statService;
    @Autowired
    private TypeMapper typeMapper;
    @Autowired
    private OrdersMapper ordersMapper;

    /**
     * 基础数据统计
     * @return
     */
    @GetMapping("/base")
    @ApiOperation("基础数据统计")
    public Result base(){
        Map<String,Object> map = statService.base();
        return Result.success(map);
    }

    /**
     * 房间类型和数量饼状图
     * @return
     */
    @GetMapping("/loadPieWithTypeAndRoomNum")
    @ApiOperation("房间类型和数量饼状图")
    public Result loadPieWithTypeAndRoomNum(){
        Map<String,Object> resultMap = statService.loadPieWithTypeAndRoomNum();
        return Result.success(resultMap);
    }

    /**
     * 房间类型订单数量折线图
     * @return
     */
    @GetMapping("/loadLineWithTypeOrderNum")
    @ApiOperation("房间类型订单数量折线图")
    public Result loadLineWithTypeOrderNum(){
        Map<String,Object> resultMap = statService.loadLineWithTypeOrderNum();
        return Result.success(resultMap);
    }


    /**
     * 当年收入统计
     * @return
     */
    @GetMapping("/loadCurYearIncome")
    @ApiOperation("当年收入统计")
    public Result loadCurYearIncome(){
        Map<String,Object> resultMap = statService.loadCurYearIncome();
        return Result.success(resultMap);
    }

    /**
     * 导出最近30天运营数据报表
     * @param response
     */
    @GetMapping("/export")
    @ApiOperation("导出最近30天运营数据报表")
    public void export(HttpServletResponse response) {
        // 设置响应头
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setHeader("Content-Disposition", "attachment; filename=operation_report.xlsx");
        statService.exportData(response);
    }
}
